﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTAdmixtureReviewService : ServiceHandle, IRPTAdmixtureReview
    {
        #region IRPTAdmixtureReview Members

        public OperationResult<List<tb_RPT_AdmixtureReview>> GetAllAdmixtureReview()
        {
            OperationResult<List<tb_RPT_AdmixtureReview>> result = new OperationResult<List<tb_RPT_AdmixtureReview>>();
            List<tb_RPT_AdmixtureReview> list = new List<tb_RPT_AdmixtureReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllAdmixtureReview();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_AdmixtureReview>> GetAdmixtureReviewByContition(string strSequence, string strProjectName, string strAdditiveFactor, string strOutSequence, string strInDate, string strTestDate)
        {
            OperationResult<List<tb_RPT_AdmixtureReview>> result = new OperationResult<List<tb_RPT_AdmixtureReview>>();
            List<tb_RPT_AdmixtureReview> list = new List<tb_RPT_AdmixtureReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAdmixtureReviewByContition( strSequence,  strProjectName,  strAdditiveFactor, 
                                                                    strOutSequence,  strInDate,  strTestDate);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_AdmixtureReview> GetAdmixtureReviewById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_AdmixtureReview> result = new OperationResult<tb_RPT_AdmixtureReview>();
            tb_RPT_AdmixtureReview admixtureReview;
            try
            {
                admixtureReview = dataContext.GetAdmixtureReviewById(id);
                if (admixtureReview == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = admixtureReview;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_AdmixtureReview> CreateAdmixtureReview(tb_RPT_AdmixtureReview entity)
        {

            OperationResult<tb_RPT_AdmixtureReview> result = new OperationResult<tb_RPT_AdmixtureReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateAdmixtureReview(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_AdmixtureReview> ModifyAdmixtureReview(tb_RPT_AdmixtureReview entity)
        {
            OperationResult<tb_RPT_AdmixtureReview> result = new OperationResult<tb_RPT_AdmixtureReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyAdmixtureReview(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_AdmixtureReview> DeleteAdmixtureReview(tb_RPT_AdmixtureReview entity)
        {
            OperationResult<tb_RPT_AdmixtureReview> result = new OperationResult<tb_RPT_AdmixtureReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteAdmixtureReview(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
